package concurrent.chapter1;

//02讲、介绍四种Singleton方式的优缺点在多线程情况下
public class SingletonObject3 {
    private static SingletonObject3 instance;

    private SingletonObject3() {
        //empty
    }

    //加synchronized关键字，实现了懒加载，防止了创建多个实例
    //但有个问题是之后的操作都是读取操作，每次要加锁，程序串行化执行，会影响性能
    public synchronized static SingletonObject3 getInstance() {
        if (null == instance)
            instance = new SingletonObject3();
        return SingletonObject3.instance;
    }

}
